<extend name="Public/base" />
<block name="title1">支付页面</block>
<block name="css"></block>
<block name="main1">



<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>购物车</title>
	<style>
		*{margin:0 auto;padding:0 auto;}
		.title{width:100%;border:1px solid #DDDDDD;height:85px;}
		.title .logo{margin-left: 100px;}
		.title .status{margin-left: 500px;}
		.tsub{width:100%;}
		.cfs a{cursor:pointer;}
		.tspan1{margin-left: 100px;}
		.tfont{font-size:20px;color:red;}
		.tp{display:inline-block;margin-left:700px;}
		.tsub2{margin-left:80px;}
		.lskdo{width:50px;}
		#btn2{background:red;width:100px;height:40px;color:white;font-size:15px;border:0px ;border-radius:4px;}
		a{cursor:pointer;}
	</style>
</head>
<body>
	<div class="title">
		<a href="<{:U('Home/Index/index')}>"><img src="__PUBLIC__/Photo/Home/Cart/logo.png" alt="logo" title='logo' class="logo"></a>
		<img src="__PUBLIC__/Photo/Home/Cart/cartstatus.png" alt="status" title='status' class="status">
	</div>
	<div class="container">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<table class="table table-hover">
					<caption >|&nbsp;我的购物车</caption>
				<thead>
					<tr>
					<th><input id="allc" type="checkbox"/>全选</th>
					<th>图片</th>
					<th>所选商品</th>
					<th>单价</th>
					<th>数量</th>
					<th>总价</th>
					<th>操作</th>
				</tr>
				</thead>	
				<form action="<{:U('Home/Cart/sess')}>" method="post" id="frm">			
				<tbody>					
					<foreach name="list" item="v">
						<foreach name="res" item="vo">	
							<if condition="$v['id'] eq $vo['id']">
								<tr id="ego_<{$v.id}>" class="showcar">
									<td><input class="choo" type="checkbox" name=ckb[] value="<{$v.sid}>" /></td>
									<td><img src='__ROOT__/Uploads/prod/<{$vo.goods_pic}>' width=80 height=80></td>
									<td><{$vo.goods_name}><br><{$v.color}><br><{$v.mobtype}><br><{$v.memory}></td>
									<td>&yen;<span class="price"><{$vo.goods_price}></span></td>
									<td class="cfs">
										<a class="jian">-</a>
										<input class="lskdo" type="text" name=num[<{$v.sid}>] value="<{$v.num}>" />
										<a class="jia">+</a>
									</td>
									<td>&yen;<span class="money"><{$vo['goods_price']*$v['num']}></span></td>
									<td><a class="btn1" data-uid="<{$v.id}>" data-sid="<{$v.sid}>">删除</a></td>
								</tr>
							</if>
						</foreach>
					</foreach>								
				</tbody>
			</table>
		</div>
	</div>
	</div>
	<div class="tsub">
		<span class="tspan1"><a href="<{:U('Home/Index/index')}>">继续购物</a>&nbsp;|&nbsp;<a class="sclean">清空购物车</a></span>
		<p class="tp">总价(不含运费):<font class="tfont">&yen;<span class="allmoney">0</span></font></p>
		<span class="tsub2"><input type="button" id="btn2" value="结算"></span>
	</div>
	</form>
	<hr width="100%" color='#DDDDDD'>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<script type="text/javascript">
//全部选中
$("#allc").change(function(){
	if($(this).prop("checked")){
		$(".choo").prop("checked",true);
		var sum=0;
		$('.choo:checked').parent().parent().find(".money").each(function(k,v){		  				
	  				sum+= parseInt($.trim($(v).text()));
	  			});				
				$('.allmoney').text(sum);
	}
	else{
		$(".choo").prop("checked",false);
		$('.allmoney').text(0);
		}
	})



//多选计算总价
$(".choo").change(function(){
	var lsmoney=$(this).parent().parent().find(".money");
	var eiow=parseInt(lsmoney.text());
	if($(this).prop("checked")){
		var now =$('.allmoney').text()*1+eiow*1;
		$('.allmoney').text(now);
	}else{
		var now =$('.allmoney').text()*1-eiow*1;
		$('.allmoney').text(now);
		}
	})
//减号键操作
$(".jian").click(function(){
	var lschoo=$(this).parent().parent().find(".choo");
	var lsoek=$(this).parent().find(".lskdo");
	var lsmoney=$(this).parent().parent().find(".money");
	var lsprice=$(this).parent().parent().find(".price");
	if(lsoek.val()>1){
		var lskoe=parseInt(lsoek.val());
		var eiow=parseInt(lsprice.text());
		lsoek.val(lskoe-1);
		var a=eiow*(lskoe-1);
		lsmoney.text(a);
		if(lschoo.prop("checked")){
			var now =$('.allmoney').text()*1-eiow*1;
			$('.allmoney').text(now);
		}else{
			var now =$('.allmoney').text();
			$('.allmoney').text(now);
		}
		}else{}
	})
//加号键操作
$(".jia").click(function(){
	var lschoo=$(this).parent().parent().find(".choo");
	var lsoek=$(this).parent().find(".lskdo");
	var lsmoney=$(this).parent().parent().find(".money");
	var lsprice=$(this).parent().parent().find(".price");	
	if(lsoek.val()<11){
		var lskoe=parseInt(lsoek.val());
		var eiow=parseInt(lsprice.text());
		lsoek.val(lskoe+1);
		var a=eiow*(lskoe+1);
		lsmoney.text(a);
		if(lschoo.prop("checked")){
			var now =$('.allmoney').text()*1+eiow*1;
			$('.allmoney').text(now);
		}else{
			var now =$('.allmoney').text();
			$('.allmoney').text(now);
		}
		}else{}
	})
//直接修改数字进行操作
$(".lskdo").on('input propertychange',function(){
	var lschoo=$(this).parent().parent().find(".choo");
	var lsmoney=$(this).parent().parent().find(".money");
	var lsprice=$(this).parent().parent().find(".price");
  	var deox=parseInt($(this).val());
  	$(this).val(deox);
  	if(isNaN(deox) || deox<1 || deox>11){
	  	alert("您好,请输入您想购买的数量,不超过11件!");
	  	$(this).val(1);
	  	lsmoney.text(lsprice.text());
	  	var sum=0;
	  	$('.choo:checked').parent().parent().find(".money").each(function(k,v){		  				
	  				sum+= parseInt($.trim($(v).text()));
	  			});
		$('.allmoney').text(sum);
	  	}else{
	  		var eiow=parseInt(lsprice.text());
	  		var a=eiow*deox;
	  		lsmoney.text(a);
	  		var sum=0;
	  		if(lschoo.prop("checked")){	  	
	  			$('.choo:checked').parent().parent().find(".money").each(function(k,v){		  				
	  				sum+= parseInt($.trim($(v).text()));
	  			});
			$('.allmoney').text(sum);				
			}else{}			
	  	}
})
//删除按钮确认事件
$(document).on('click','.btn1',function(){
	var uid=$(this).attr('data-uid');
	var sid=$(this).attr('data-sid');
	var lsmoney=$(this).parent().parent().find(".money");
	var lschoo=$(this).parent().parent().find(".choo");
	$( "<div>确认删除吗???</div>" ).dialog({
			title:'删除',
			modal: true,
			buttons: {
		        确定: function(){
		          	$.get('<{:U("del")}>',{uid:sid},function(data){
						if(data.status){				
							$('#ego_'+uid).remove();
							
							if(lschoo.prop("checked")){	  	
								$('.allmoney').text($('.allmoney').text()-lsmoney.text());
							}			
						}else{
							alert('删除失败');
						}			
					},'json');
		          	$(this).dialog( "close" );
		        },
		        取消: function(){
		        	$(this).dialog( "close" );
		        }
			}
		});
});
//清空购物车
$('.sclean').click(function(){			
			$( "<div>确认清空购物车???</div>" ).dialog({
					title:'删除',
					modal: true,
					buttons: {
				        确定: function(){				       
				          	$.post('<{:U("sclean")}>',function(data){
								if(data.status){				
									$('.showcar').remove();		
								}else{
									alert('删除失败');
								}			
							},'json');
				          	$(this).dialog( "close" );
				        },
				        取消: function(){
				        	$(this).dialog( "close" );
				        }
					}
				});
		});

//传值跳转
$('#btn2').click(function(){	
	if($('.choo').is(':checked')){
		var arr=[];
		$('.choo:checked').each(function(k,v){
			arr=$(v).text();
		});
		$('.choo:checked').parent().parent().find(".lskdo").each(function(k,v){
			num=$(v).val();
		});
		var all=$('.allmoney').text();
		$.post('<{:U("ptype")}>',{uids:arr,all:all},function(data){
			
		});
		$('#frm').submit();
	}else{
		alert('请先选择要购买的商品!');
	}
})

</script>
</body>
</html>
</block>